var reviveCount = 5;
var mapIds = [940204040, 940204050, 940204060];
var 准备地图 = 450006400;
var eventName = "莫拉斯_剧情_战斗1";

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance(eventName);
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully()
    }
    return c
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0));
    b.startEventTimer(1000 * 60 * 10)
}

function onPlayerRevived(b, a) {
    return false
}

function onMonsterDamaged(b, a, d, e, c) {}

function onMonsterKilled(b, e, c) {
    var d = em.getNumberProperty("state");
    var g = p.getMapId();
    if (g == 940204040) {
        var f = 28
    } else {
        if (g == 940204050) {
            var f = 17
        } else {
            var f = 18
        }
    }
    var a = em.getNumberProperty("stage" + d + "_kill") + 1;
    em.setProperty("stage" + d + "_kill", a);
    b.getPlayers().forEach(function (h) {
        if (a < f) {
            h.dropMessage(-1, "消灭数量：" + (a) + "/" + f)
        }
    });
    if (a >= f) {
        em.setProperty("stage" + d, "clear");
        em.setProperty("stage" + d + "_kill", 0);
        b.getPlayers().forEach(function (h) {
            h.getAPI().fieldEffect_ScreenMsg("monsterPark/clear");
            h.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100);
            setupTask = em.schedule("Chuansong", 1000 * 1 * 3, b)
        })
    }
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    switch (a) {
        case 940204040:
            initProp("stage" + 1 + "_kill", 0);
            break;
        case 940204050:
            initProp("stage" + 1 + "_kill", 0);
            break;
        case 940204060:
            initProp("stage" + 1 + "_kill", 0);
            break
    }
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function Chuansong(b, a) {
    if (b.getMapInstance(940204040).getCharactersSize() != 0) {
        warp(b, 940204050, 0)
    } else {
        if (b.getMapInstance(940204050).getCharactersSize() != 0) {
            warp(b, 940204060, 0)
        } else {
            if (b.getMapInstance(940204060).getCharactersSize() != 0) {
                warp(b, 450006440, 0)
            }
        }
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function warp(d, c, a) {
    for (var b = 0; b < d.getPlayerCount(); b++) {
        d.getPlayers().get(b).getAPI().warp(c, a)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onItemPickedUp() {};